package com.ruoyi.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.domain.HeartRate;
import com.ruoyi.service.HeartRateService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: HeartRateController
 * @Description:
 * @author: lifei
 * @date: 2025年01月16日 15:38
 */
@RestController
@RequestMapping("/kangyue/userHeartRate")
public class HeartRateController extends BaseController {

    private final HeartRateService heartRateService;

    public HeartRateController(HeartRateService heartRateService) {
        this.heartRateService = heartRateService;
    }

    /**
     * 获取用户五秒内五次心率数据
     *
     * @param userId 用户ID
     * @return 血压数据列表
     */
    @GetMapping("/lastfiveheartrate")
    public TableDataInfo getLastFiveHeartRate(@RequestParam long userId) {
        List<HeartRate> fiveHeartRate = heartRateService.selectLastFiveHeartRate(userId);
        return getDataTable(fiveHeartRate);
    }

    /**
     * 获取最近一周心率数据
     *
     * @return 一周心率数据列表
     */
    @GetMapping("/weekHeartRate")
    public TableDataInfo getWeekHeartRate(@RequestParam long userId) {
        List<HeartRate> heartRateList = heartRateService.selectWeekHeartRate(userId);
        heartRateList.forEach(heartRate -> {
            if (heartRate.getUserId() == null) {
                heartRate.setUserId(userId);
            }
        });
        return getDataTable(heartRateList);
    }

}
